<%--
  Created by IntelliJ IDEA.
  User: xiaoji
  Date: 2014/11/24
  Time: 14:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set value="${pageContext.request.contextPath}" var="path" scope="session"/>
<!DOCTYPE html>

<html>
<head>
    <title>仲裁管理</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="${path}/plugins/jquery-easyui-1.4.1/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="${path}/plugins/jquery-easyui-1.4.1/themes/icon.css">
    <script type="text/javascript" src="${path}/plugins/jquery-easyui-1.4.1/jquery.min.js"></script>
    <script type="text/javascript" src="${path}/plugins/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${path}/plugins/jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        $(function(){
            //查询
            $("#search").click(function(){
                var currenttab =  $("#search").attr("stab");
                $('#'+currenttab).datagrid('load',{
                    applyReason:$("#applyReason").val()
                });
            });
            //切换
            $('#tabs').tabs({
                onSelect: function (title) {
                    if(title=="全部"){
                        $('#ttAll').datagrid({
                            url:'${path}/arbitration/view.do',
                            method:'get'
                        });
                        $("#search").attr("stab","ttAll");
                    }else if(title=="未仲裁"){
                        $('#tt101002').datagrid({
                            url:'${path}/arbitration/view.do?arbitrateStatus=101002',
                            method:'get'
                        });
                        $("#search").attr("stab","tt101002");
                    }else if(title=="已仲裁"){
                        $('#tt101001').datagrid({
                            url:'${path}/arbitration/view.do?arbitrateStatus=101001',
                            method:'get'
                        });
                        $("#search").attr("stab","tt101001");
                    }
                }
            });
        });
    </script>
</head>
<body class="easyui-layout">
<div region="center" style="padding:5px;" border="false">
    <div id="tabs" class="easyui-tabs" style="width:100%;height:700px">
        <div title="全部" style="padding:10px">
            <!--列表-->
            <table id="ttAll" class="easyui-datagrid"
                   data-options="singleSelect:true,collapsible:true,url:'${path}/arbitration/view.do',
       method:'get',toolbar:'#tb',pagination:'true',fit:'true'">
                <thead>
                <tr>
                    <th data-options="field:'reason',align:'center',width:180">仲裁原因</th>
                    <th data-options="field:'time',align:'center',width:150">申请仲裁时间</th>
                    <th data-options="field:'STATUS',align:'center',width:80,formatter:function(v){if(v == 101001) return '已仲裁'; else return '未仲裁';}">状态</th>
                    <th data-options="field:'result',align:'center',width:80">仲裁结果</th>
                    <th data-options="field:'title',align:'center',width:80">合同标题</th>
                    <th data-options="field:'itemTitle',align:'center',width:80">任务标题</th>
                    <th data-options="field:'id',align:'center',width:200,formatter: rowformatter">操作</th>
                </tr>
                </thead>
            </table>
        </div>
        <div title="未仲裁" style="padding:10px">
            <table id="tt101002" class="easyui-datagrid"
                   data-options="singleSelect:true,collapsible:true,url:null,
       method:'get',toolbar:'#tb',pagination:'true',fit:'true'">
                <thead>
                <tr>
                    <th data-options="field:'reason',align:'center',width:180">仲裁原因</th>
                    <th data-options="field:'time',align:'center',width:150">申请仲裁时间</th>
                    <th data-options="field:'STATUS',align:'center',width:80,formatter:function(v){if(v == 101001) return '已仲裁'; else return '未仲裁';}">状态</th>
                    <th data-options="field:'result',align:'center',width:80">仲裁结果</th>
                    <th data-options="field:'title',align:'center',width:80">合同标题</th>
                    <th data-options="field:'itemTitle',align:'center',width:80">任务标题</th>
                    <th data-options="field:'id',align:'center',width:200,formatter: rowformatter2">操作</th>
                </tr>
                </thead>
            </table>
        </div>
        <div title="已仲裁" style="padding:10px">
            <table id="tt101001" class="easyui-datagrid"
                   data-options="singleSelect:true,collapsible:true,url:null,
       method:'get',toolbar:'#tb',pagination:'true',fit:'true'">
                <thead>
                <tr>
                    <th data-options="field:'reason',align:'center',width:180">仲裁原因</th>
                    <th data-options="field:'time',align:'center',width:150">申请仲裁时间</th>
                    <th data-options="field:'STATUS',align:'center',width:80,formatter:function(v){if(v == 101001) return '已仲裁'; else return '未仲裁';}">状态</th>
                    <th data-options="field:'result',align:'center',width:80">仲裁结果</th>
                    <th data-options="field:'title',align:'center',width:80">合同标题</th>
                    <th data-options="field:'itemTitle',align:'center',width:80">任务标题</th>
                    <th data-options="field:'id',align:'center',width:200,formatter: rowformatter">操作</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<!--头工具项-->
<div id="tb" style="padding:2px 5px;">
    仲裁原因: <input class="easyui-textbox" name="applyReason" id="applyReason" style="width:110px">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="search" stab="ttAll">查找</a>
</div>
<div id="w" class="easyui-window" title="仲裁论述记录" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:600px;height:400px;padding:10px;">
    <div style="padding:10px 10px 10px 10px" id="itemDetail">
        <div class="easyui-panel" title="仲裁论述记录">
            <table border="1px" cellpadding="0" cellspacing="0" bordercolor= "#95B8E7" width="100%">
                <tr>
                    <th>头像</th>
                    <th>论述内容</th>
                </tr>
                <tbody id="discuss">

                </tbody>

            </table>
        </div>
    </div>
</div>
<!--仲裁-->
<div id="w2" class="easyui-window" title="仲裁" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:600px;height:400px;padding:10px;">
    <div style="padding:10px 10px 10px 10px">
        <div class="easyui-panel" title="仲裁" style="padding:10px 10px 10px 10px">
            <p>仲裁描述：</p>
            <p><textarea id="result" style="width: 95%;height: 200px"></textarea></p>
            <p><a href="javascript:void(0)" class="easyui-linkbutton" onclick="save()">仲裁</a></p>
            <input type="hidden" id="arbitrateId">
            <input type="hidden" id="lastIndex">
        </div>
    </div>
</div>
<script>
    function rowformatter(value,row,index){
        var str = "";
        if(row.STATUS == 101002){
            return  '<a href="#" onclick="showItemDetail('+index+')">查看论述记录</a>&nbsp;&nbsp;'+
                    '<a href="#" onclick="javascript:openw2('+row.id+','+index+');">仲裁</a>';
        }else{
            return  '<a href="#" onclick="showItemDetail('+index+')">查看论述记录</a>';
        }

    }
    function rowformatter2(value,row,index){
        return  '<a href="#" onclick="showItemDetail('+index+')">查看论述记录</a>&nbsp;&nbsp;'+
                '<a href="#" onclick="javascript:openw2('+row.id+','+index+');">仲裁</a>';
    }
    function showItemDetail(index){
        var currenttab =  $("#search").attr("stab");
        //本行数据
        var row = $('#'+currenttab).datagrid('getData').rows[index];
        //阶段数据
        $.post("${path}/arbitration/discuss.do",{
            id:row.id
        },function(data){
            var list = data.list;
            if(list.length > 0){
                var htmlstr = "";
                for(var i=0;i<list.length;i++){
                    var obj = list[i];
                    var deliverable = "";
                    if(obj.deliverable != ''){
                        deliverable+="<img src='${path}/style/common/images/zip.jpg' width='40px' height='40px'><br/>";
                    }
                    var imgs = "";
                    if(obj.attachment!=undefined){
                        var imgarr = obj.attachment.split(",");
                        for(var j=0;j<imgarr.length;j++){
                            imgs+="<img src='/"+imgarr[j]+"' width='40px' height='40px'>";
                        }
                    }

                    htmlstr+="<tr>" +
                            "<td><img  width='40px' height='40px' src='/"+obj.pic+"'><br/>"+obj.user_name+"</td>" +
                            "<td><p>"+obj.content+"</p>"+
                            "<p>"+imgs+"<p>"+
                            "<p>"+obj.time+"<p>"+
                            "</td>" +
                            "</tr>";
                }
                $("#discuss").html(htmlstr);
            }else{
                $("#discuss").html("暂无论述记录");
            }
        },"json");
        $('#w').window('open');
    }

    function openw2(id,index){
        $("#arbitrateId").val(id);
        $("#lastIndex").val(index);
        $('#w2').window('open');
    }
    //仲裁保存
    function save(){
        if($("#result").val() != ''){
            $.post("${path}/arbitration/examine.do",{
                id:$("#arbitrateId").val(),
                result:$("#result").val()
            },function(data){
                if(data.errormsg == undefined){
                    $('#tt101002').datagrid('updateRow', {
                        index:$("#lastIndex").val(),
                        row : {
                            result:$("#result").val()
                        }
                    });
                    $("#arbitrateId").val("");
                    $("#lastIndex").val("");
                    $('#w2').window('close');
                }else{
                    alert(data.errormsg);
                }
            },"json");
        }else{
            alert("仲裁结果不能为空！");
        }
    }
</script>
</body>
</html>
